import os
import shutil
from subprocess import Popen, PIPE


class FileSystemHelper(object):
    def createFolder(self, folder):
        os.makedirs(folder)

    def deleteFolder(self, folder):
        if os.path.exists(folder):
            shutil.rmtree(folder)

    def recreateFolder(self, folder):
        self.deleteFolder(folder)
        self.createFolder(folder)


class OSHelper(object):
    def execCapture(self, command, waitUntilFinish = True):
        p = Popen(command, shell = True, stdout = PIPE, stderr = PIPE)
        #out, error = p.communicate()
        if waitUntilFinish:
            out, error = p.communicate()
            result = out if out else error
            return result.replace(os.linesep, '\n')
        else:
            return 'Process started'